package com.zhaoxi.project.sys.service;

import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.sys.mapper.SlideshowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//样例
@Service
public class SlideshowService extends BaseService {

  @Autowired
  private SlideshowMapper slideshowMapper;

  //查询数据集合
  public List<PageData> getList(PageData pd) {
    return slideshowMapper.getList(pd);
  }
  //查询数据对象 通过id
  public PageData getById(PageData pd) {
    PageData pd1 = new PageData();
    if (pd.getLong("id") == null){
      return null;
    }
    pd1.put("id",pd.getLong("id"));
    List<PageData> list = slideshowMapper.getList(pd1);
    if (list.size() > 0){
      return list.get(0);
    }
    return null;
  }

  //查询数据对象 是否有重复的，可设置id，同一个id并不是重复。
  public int checkUnique(PageData pd) {
    String userId = pd.getString("id");
    pd.put("id",null);
    List<PageData> list = slideshowMapper.getList(pd);
    int i = 0;
    for (PageData k : list){
      if (! k.getString("id").equals(userId)){
        i ++;
      }
    }
    return i;
  }



  //新增
  public PageData add(PageData pd) {
    return this.responses(slideshowMapper.add(pd));
  }
  //更新
  public PageData edit(PageData pd) {
    return this.responses(slideshowMapper.edit(pd));
  }
  //删除
  public PageData del(Long id) {
    return this.responses(slideshowMapper.del(id));
  }
}
